package com.g8.pethospitallearnbackend.mapper;

import com.g8.pethospitallearnbackend.entity.Lab;
import com.g8.pethospitallearnbackend.entity.Medicine;
import com.g8.pethospitallearnbackend.entity.MedicineExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface MedicineMapper {
    @SelectProvider(type=MedicineSqlProvider.class, method="countByExample")
    long countByExample(MedicineExample example);

    @DeleteProvider(type=MedicineSqlProvider.class, method="deleteByExample")
    int deleteByExample(MedicineExample example);

    @Delete({
        "delete from medicine",
        "where medicine_id = #{medicineId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String medicineId);

    @Insert({
        "insert into medicine (medicine_id, medicine_name, ",
        "medicine_price, medicine_desc, ",
        "medicine_measure, medicine_warning)",
        "values (#{medicineId,jdbcType=VARCHAR}, #{medicineName,jdbcType=VARCHAR}, ",
        "#{medicinePrice,jdbcType=DOUBLE}, #{medicineDesc,jdbcType=LONGVARCHAR}, ",
        "#{medicineMeasure,jdbcType=LONGVARCHAR}, #{medicineWarning,jdbcType=LONGVARCHAR})"
    })
    int insert(Medicine record);

    @InsertProvider(type=MedicineSqlProvider.class, method="insertSelective")
    int insertSelective(Medicine record);

    @SelectProvider(type=MedicineSqlProvider.class, method="selectByExampleWithBLOBs")
    @Results({
        @Result(column="medicine_id", property="medicineId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="medicine_name", property="medicineName", jdbcType=JdbcType.VARCHAR),
        @Result(column="medicine_price", property="medicinePrice", jdbcType=JdbcType.DOUBLE),
        @Result(column="medicine_desc", property="medicineDesc", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="medicine_measure", property="medicineMeasure", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="medicine_warning", property="medicineWarning", jdbcType=JdbcType.LONGVARCHAR)
    })
    List<Medicine> selectByExampleWithBLOBs(MedicineExample example);

    @SelectProvider(type=MedicineSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="medicine_id", property="medicineId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="medicine_name", property="medicineName", jdbcType=JdbcType.VARCHAR),
        @Result(column="medicine_price", property="medicinePrice", jdbcType=JdbcType.DOUBLE)
    })
    List<Medicine> selectByExample(MedicineExample example);

    @Select({
        "select",
        "medicine_id, medicine_name, medicine_price, medicine_desc, medicine_measure, ",
        "medicine_warning",
        "from medicine",
        "where medicine_id = #{medicineId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="medicine_id", property="medicineId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="medicine_name", property="medicineName", jdbcType=JdbcType.VARCHAR),
        @Result(column="medicine_price", property="medicinePrice", jdbcType=JdbcType.DOUBLE),
        @Result(column="medicine_desc", property="medicineDesc", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="medicine_measure", property="medicineMeasure", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="medicine_warning", property="medicineWarning", jdbcType=JdbcType.LONGVARCHAR)
    })
    Medicine selectByPrimaryKey(String medicineId);

    @UpdateProvider(type=MedicineSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Medicine record, @Param("example") MedicineExample example);

    @UpdateProvider(type=MedicineSqlProvider.class, method="updateByExampleWithBLOBs")
    int updateByExampleWithBLOBs(@Param("record") Medicine record, @Param("example") MedicineExample example);

    @UpdateProvider(type=MedicineSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Medicine record, @Param("example") MedicineExample example);

    @UpdateProvider(type=MedicineSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Medicine record);

    @Update({
        "update medicine",
        "set medicine_name = #{medicineName,jdbcType=VARCHAR},",
          "medicine_price = #{medicinePrice,jdbcType=DOUBLE},",
          "medicine_desc = #{medicineDesc,jdbcType=LONGVARCHAR},",
          "medicine_measure = #{medicineMeasure,jdbcType=LONGVARCHAR},",
          "medicine_warning = #{medicineWarning,jdbcType=LONGVARCHAR}",
        "where medicine_id = #{medicineId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKeyWithBLOBs(Medicine record);

    @Update({
        "update medicine",
        "set medicine_name = #{medicineName,jdbcType=VARCHAR},",
          "medicine_price = #{medicinePrice,jdbcType=DOUBLE}",
        "where medicine_id = #{medicineId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Medicine record);

    @Select("select medicine_id from medicine where medicine_name=#{medicineName}")
    String selectMedicineIdByName(@Param("medicineName") String medicineName);

    @Select("select * from medicine where medicine_id=#{medicineId};")
    Medicine selectMedicineById(@Param("medicineId") String med);
}